package ripple.common;

public class DelayInjection {
    public static int E2EDelay;
    public static int E2CDelay;
    public static int C2CDelay;

    public static int BASE;

    public static int DIVIDER;

    public static void injectDelay(int sourceId, int currentId) {
        try {
            if (sourceId / BASE > DIVIDER && currentId / BASE > DIVIDER) {
//                DebugTool.write(DebugTool.buildInfo(DelayInjection.class , "injectDelay"
//                        , "source id: " + sourceId
//                                + ", current id: " + currentId
//                                + ", inject E2EDelay" +
//                                ", sleep: " + E2EDelay
//                        ));

                Thread.sleep(E2EDelay);
            } else if (sourceId / BASE < DIVIDER && currentId / BASE < DIVIDER) {
                Thread.sleep(C2CDelay);
//                DebugTool.write(DebugTool.buildInfo(DelayInjection.class , "injectDelay"
//                        , "source id: " + sourceId
//                                + ", current id: " + currentId
//                                + ", inject C2CDelay" +
//                                ", sleep: " + C2CDelay
//                ));
            } else {
                Thread.sleep(E2CDelay);
//                DebugTool.write(DebugTool.buildInfo(DelayInjection.class , "injectDelay"
//                        , "source id: " + sourceId
//                                + ", current id: " + currentId
//                                + ", inject E2CDelay" +
//                                ", sleep: " + E2CDelay
//                ));
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

    }

    public static void injectE2EDelay(){
        try {
            Thread.sleep(DelayInjection.E2EDelay);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
